package logic

import (
	"context"
	"practice-one/userrpc/userrpc"

	"practice-one/api/internal/svc"
	"practice-one/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsListLogic {
	return &GoodsListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GoodsListLogic) GoodsList(req *types.GoodsListRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	data, err := l.svcCtx.UserRpc.GoodsList(l.ctx, &userrpc.GoodsListRequest{
		Page:      req.Page,
		Size:      req.Size,
		Title:     req.Title,
		GoodsType: req.GoodsType,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "商品展示成功",
		Code:    200,
		Data:    data,
	}, nil
}
